home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1997 May / PC Plus Super CD Issue 127 (May 1997).iso / handson / java / classes / frame1.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-02-07  |  5.1 KB  |  150 lines

  1. import java.awt.Button;
  2. import java.awt.Component;
  3. import java.awt.Container;
  4. import java.awt.Event;
  5. import java.awt.FileDialog;
  6. import java.awt.Frame;
  7. import java.awt.LayoutManager;
  8. import java.awt.List;
  9. import java.awt.Menu;
  10. import java.awt.MenuBar;
  11. import java.awt.MenuItem;
  12. import java.util.Enumeration;
  13. import java.util.Vector;
  14.  
  15. public class Frame1 extends Frame {
  16.    // $FF: renamed from: v java.util.Vector
  17.    Vector field_0;
  18.    FileDialog OpenFileDialog;
  19.    List list1;
  20.    Button button1;
  21.    MenuBar mainMenuBar;
  22.    Menu menu1;
  23.    Menu menu2;
  24.    Menu menu3;
  25.  
  26.    void button1_Clicked(Event event) {
  27.       this.list1.clear();
  28.  
  29.       for(Enumeration e = this.field_0.elements(); e.hasMoreElements(); this.list1.addItem("--------------------")) {
  30.          Thing t = (Thing)e.nextElement();
  31.          this.list1.addItem(t.getName());
  32.          this.list1.addItem(t.getDescription());
  33.          if (t instanceof Object) {
  34.             this.list1.addItem("[This is an Object]");
  35.          }
  36.  
  37.          if (t instanceof Thing) {
  38.             this.list1.addItem("[This is a Thing]");
  39.          }
  40.  
  41.          if (t instanceof Creature) {
  42.             this.list1.addItem("[This is a Creature] species = " + ((Creature)t).getSpecies());
  43.          }
  44.  
  45.          if (t instanceof Treasure) {
  46.             this.list1.addItem("[This is a Treasure] value = " + ((Treasure)t).getValue());
  47.          }
  48.       }
  49.  
  50.    }
  51.  
  52.    void Open_Action(Event event) {
  53.       this.OpenFileDialog.show();
  54.    }
  55.  
  56.    void About_Action(Event event) {
  57.       (new AboutDialog(this, "About...", false)).show();
  58.    }
  59.  
  60.    void Exit_Action(Event event) {
  61.       (new QuitDialog(this, "Quit the Application?", false)).show();
  62.    }
  63.  
  64.    public Frame1() {
  65.       this.field_0 = new Vector();
  66.       ((Container)this).setLayout((LayoutManager)null);
  67.       ((Frame)this).addNotify();
  68.       ((Component)this).resize(((Container)this).insets().left + ((Container)this).insets().right + 431, ((Container)this).insets().top + ((Container)this).insets().bottom + 464);
  69.       this.OpenFileDialog = new FileDialog(this, "Open", 0);
  70.       this.list1 = new List(0, false);
  71.       ((Container)this).add(this.list1);
  72.       this.list1.reshape(((Container)this).insets().left + 7, ((Container)this).insets().top + 8, 416, 345);
  73.       this.button1 = new Button("Display My Objects!");
  74.       this.button1.reshape(((Container)this).insets().left + 133, ((Container)this).insets().top + 383, 159, 39);
  75.       ((Container)this).add(this.button1);
  76.       ((Frame)this).setTitle("A Basic Application");
  77.       this.mainMenuBar = new MenuBar();
  78.       this.menu1 = new Menu("File");
  79.       this.menu1.add("Open...");
  80.       this.menu1.add("Save");
  81.       this.menu1.add("Save As...");
  82.       this.menu1.addSeparator();
  83.       this.menu1.add("Exit");
  84.       this.mainMenuBar.add(this.menu1);
  85.       this.menu2 = new Menu("Edit");
  86.       this.menu2.add("Cut");
  87.       this.menu2.add("Copy");
  88.       this.menu2.add("Paste");
  89.       this.mainMenuBar.add(this.menu2);
  90.       this.menu3 = new Menu("Help");
  91.       this.menu3.add("About");
  92.       this.mainMenuBar.add(this.menu3);
  93.       ((Frame)this).setMenuBar(this.mainMenuBar);
  94.    }
  95.  
  96.    public Frame1(String title) {
  97.       this();
  98.       ((Frame)this).setTitle(title);
  99.    }
  100.  
  101.    public synchronized void show() {
  102.       ((Component)this).move(50, 50);
  103.       super.show();
  104.       this.field_0.addElement(new Thing("A Wotsit", "An ordinary Thing"));
  105.       this.field_0.addElement(new Creature("A Troll", "A nasty fellow", "Trollus trollidus"));
  106.       this.field_0.addElement(new Treasure("A Sword", "A jewel-encrusted weapon", 550));
  107.    }
  108.  
  109.    public boolean handleEvent(Event event) {
  110.       if (event.id == 201) {
  111.          ((Component)this).hide();
  112.          ((Frame)this).dispose();
  113.          System.exit(0);
  114.          return true;
  115.       } else {
  116.          if (event.target == this.button1 && event.id == 1001) {
  117.             this.button1_Clicked(event);
  118.          }
  119.  
  120.          return super.handleEvent(event);
  121.       }
  122.    }
  123.  
  124.    public boolean action(Event event, Object arg) {
  125.       if (event.target instanceof MenuItem) {
  126.          String label = (String)arg;
  127.          if (label.equalsIgnoreCase("Open...")) {
  128.             this.Open_Action(event);
  129.             return true;
  130.          }
  131.  
  132.          if (label.equalsIgnoreCase("About")) {
  133.             this.About_Action(event);
  134.             return true;
  135.          }
  136.  
  137.          if (label.equalsIgnoreCase("Exit")) {
  138.             this.Exit_Action(event);
  139.             return true;
  140.          }
  141.       }
  142.  
  143.       return super.action(event, arg);
  144.    }
  145.  
  146.    public static void main(String[] args) {
  147.       (new Frame1()).show();
  148.    }
  149. }
  150.